package ligne2vie.topos.server.service;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * The class {@link SummitServiceLogOutTestCase} verifies if the class {@link SummitServiceImpl} correctly works in an
 * independent way from the Web Interface, when the user is logged in.
 * 
 * @author thuguerre
 * @since 1.0.0
 */
public class SummitServiceLogOutTestCase extends AbstractSummitServiceTestCase {

	@Before
	public void setUp() {

		super.setUp();

		userLogout();
	}

	@After
	public void tearDown() {
		super.tearDown();
	}

	/**
	 * Verify, if user is not logged in, method createSummit correctly fails.
	 */
	@Test
	public void impossibleToCreateSummit() {

		try {

			createSummit();
			fail("Should have thrown exception");

		} catch (RuntimeException ex) {

			assertTrue(ex.getMessage().equals("User should be authenticated."));
			assertEquals(0, service.getAllSummits().size());
		}
	}
	
	/**
	 * Verify, if user is not logged in, method editSummit correctly fails.
	 */
	@Test
	public void impossibleToEditSummit() {

		try {

			editSummit(INEXISTENT_SUMMIT_ID);
			fail("Should have thrown exception");

		} catch (RuntimeException ex) {

			assertTrue(ex.getMessage().equals("User should be authenticated."));
			assertEquals(0, service.getAllSummits().size());
		}
	}
	
	/**
	 * Verify, if user is not logged in, method removeSummit correctly fails.
	 */
	@Test
	public void impossibleToRemoveSummit() {

		try {

			removeSummit(INEXISTENT_SUMMIT_ID);
			fail("Should have thrown exception");

		} catch (RuntimeException ex) {

			assertTrue(ex.getMessage().equals("User should be authenticated."));
			assertEquals(0, service.getAllSummits().size());
		}
	}
}
